Behaviors > The behavior API > behaviorFunction()

 

behaviorFunction()

Description

Inserts one or more functions—surrounded by <SCRIPT LANGUAGE="JavaScript"></SCRIPT> tags, if none yet exist—into the HEAD of the user's document.

Arguments

None.

Returns

Either a string containing the JavaScript functions to be inserted in the user's document, or a string containing the names of the functions to be inserted into the user's document. This value must be exactly the same every time (it cannot depend on input from the user). The functions are inserted only once, regardless of how many times the action is applied to elements in the document.

Note: Quotation marks within the returned string must be preceded by a backslash (\) to avoid errors reported by the JavaScript interpreter.

Example

The following instance of behaviorFunction() returns a function called MM_popupMsg():

function behaviorFunction(){
	return ""+
	"function MM_popupMsg(theMsg) { //v1.0\n"+
	"  alert(theMsg);\n"+
	"}";
}

The following code would be equivalent to the preceding behaviorFunction() declaration, and is the method used to declare behaviorFunction() in all behaviors shipped with Dreamweaver:

function MM_popupMsg(theMsg){ //v1.0
	alert(theMsg);
}

function behaviorFunction(){
	return "MM_popupMsg";
}